package com.tool;

import cn.com.tiza.tstar.common.entity.TStarData;

import java.nio.charset.Charset;
import java.sql.SQLException;
import java.util.List;

/**
 * Created by Administrator on 2018-4-18.
 */
public class dbTest {
    public static void main(String[] args) throws SQLException {
//        db oradb = new db();
//        List<String> vlist = oradb.querydeviceID("SELECT DISTINCT(ID) FROM DBD_VEHICLE WHERE PRODUCTTYPEID=1058 AND ISDELETED=0", false);
//        int ii = 0;
//kafka测试
        TStarData tStarData=new TStarData();
        String data="03A010A00FA0FFFFFF90";
        byte[] input= hexStringToByte(data);
        String tt="{\"timestamp\":\"2018-04-19 13:56:12.743\",\"values\":{\"id\":\"ns=2;s=Machines/Machine B/TestValueInt\",\"v\":\"13752\",\"q\":\"Good\",\"t\":\"2018-04-19 03:40:11.851\"}}";
        String tt1="{\"VehicleWorkStatus\":0,\"AdminDivisionCode\":\"320303\",\"gpsTime\":\"2018-04-18 00:27:29\",\"altitude\":89,\"direction\":0,\"lng\":117.230772,\"PowerOff\":0,\"SwitchStatus\":0,\"WorkDataTime\":\"2018-04-18 00:27:29\",\"LocationStatus\":1,\"TerminalId\":\"150711\",\"GpsAntennaShort\":0,\"LockStatus\":0,\"GpsHealthStatus\":0,\"OverSpeedStatus\":0,\"GpsAntennaBreak\":0,\"EncryptLng\":117.23649141675773,\"VehicleId\":\"139957\",\"AccStatus\":1,\"GpsModuleFault\":0,\"VoltLowerThanThreshold\":0,\"EncryptLat\":34.261066225452076,\"lat\":34.26235,\"ChargingStatus\":1,\"speed\":0,\"OpenCapStatus\":0,\"VehicleHealthStatus\":0,\"TowedStatus\":0,\"gpsPlace\":0,\"FunctionCode\":\"XCMG-LRC-II-XF\",\"GpsWorkStatus\":0,\"LowVoltage\":0,\"CanCommunicationFault\":0}";
        tStarData.setTerminalID("A0C11804000001");
        tStarData.setCmdSerialNo(1);
        tStarData.setCmdID(3);
        tStarData.setMsgBody(data.getBytes(Charset.forName("UTF-8")));
        tStarData.setTime(System.currentTimeMillis());
        KafkaStore kafkaStore=new KafkaStore();
        kafkaStore.writeKafka(tStarData);

        db mysqltest = new db();

        List<String> hiscmd = mysqltest.querycmd("select * from roadhis where deviceid='64708302743'", true);
        int i = 0;
        for (String item : hiscmd
                ) {
            System.out.println(item);
        }
//        db test = new db();
//        try {
//            test.query("drop table student");
//        } catch (SQLException e) {}
//        List<String> queryID=test.queryID("select * from t_terminal where terminal_type_id=4 and terminal_id like 'A%'", true);
//        int i=0;
//        for (String item:queryID
//                ) {
//            if(i>=3299){break;}
//            String newid="L"+item.substring(1);
//            long now=System.currentTimeMillis();
//            test.query("insert into t_terminal(register_time,terminal_type_id,terminal_id) values("+now+",4,"+"'"+newid+"'"+")");
//            i++;
//        }
//        test.close();
    }

    public static byte[] hexStringToByte(String hex) {
        int len = (hex.length() / 2);
        byte[] result = new byte[len];
        char[] achar = hex.toCharArray();
        for (int i = 0; i < len; i++) {
            int pos = i * 2;
            result[i] = (byte) (toByte(achar[pos]) << 4 | toByte(achar[pos + 1]));
        }
        return result;
    }

    private static int toByte(char c) {
        byte b = (byte) "0123456789ABCDEF".indexOf(c);
        return b;
    }
}
